from os.path import join
import sys

ROOT = "../evaluation"
LAT_FCTR = float(10000*1000*1000)
OPS_FCTR = float(10000*1000*1000*1000)


def read_file(filename):
    lines = []
    with open(filename, 'r') as f:
        for line in f:
            if line.startswith("Timer 13 MEAN"):
                lines.append(line)

    line = lines[-1]
    time = int(line.split(",")[0].split(":")[1])
    return time


def ycsb():
    print("result of YCSB:\n")
    workloads = ["a", "b", "c", "d", "e", "f"]
    # workloads = ["e", "f"]
    # datasets = ['ycsb', 'ar_19', 'osm_19']
    datasets = ['idf_351_valid_19']
    # prefix = ["10K", "33K", "20K", "650K0-10M0_zipfian"]
    prefix = ["650K0-10M0_zipfian"]
    # prefix = []


    for w in workloads:
        for (d, p) in zip(datasets, prefix):
            base = read_file(join(ROOT, "{}_random_baseline_ycsb-{}-{}.txt".format(d, w, p)))
            llsm = read_file(join(ROOT, "{}_random_llsm_ycsb-{}-{}.txt".format(d, w, p)))
            print("{} baseline on workload ycsb-{}-{} throughput: {:.2f} kops/sec".format(d, w, p, OPS_FCTR/base))
            print("{} llsm on workload ycsb-{}-{} throughput: {:.2f} kops/sec".format(d, w, p, OPS_FCTR/llsm))
            print("")


def main():
    ycsb()
    print("ycsb collect results - done")


if __name__ == '__main__':
    main()
